<?php
error_reporting(E_ALL & ~E_NOTICE);
(new package())->begin();

class package
{
    public $num     = 199;
    public $package = [70, 30, 20, 10];
    public $result  = [];

    public function make($count, $package, $result = [])
    {
        if ($package_type = array_shift($package)) {
            if (empty($package)) {
                $num = (int)($count / $package_type);
                if ($mod = $count % $package_type) {
                    $num += 1;
                }
                $result[ $package_type ] = $num;
                $this->result[] = $result;
            } else {
                for ($i = 0; $i <= (int)($count / $package_type); $i++) {
                    $result[ $package_type ] = $i;
                    if ($num = $count - $i * $package_type) {
                        $this->make($num, $package, $result);
                    } else {
                        $this->result[] = $result;
                        return;
                    }
                }
            }

        }

    }

    public function begin()
    {
        $num = min(10000, intval($_GET['n'])) ?: $this->num;
        $pack = array_filter(array_map('intval', explode(',', $_GET['p']))) ?: $this->package;
        $this->make($num, $pack);
        var_dump(['num' => $num, 'package' => $pack]);
        foreach ($this->result as $k => $v) {
            echo "$k: ";
            foreach ($v as $kk => $vv) {
                echo "$vv * $kk = " . ($vv * $kk) . ', ';
            }
            echo '<br>';
        }
    }
}
